﻿//-----------------------------------------------------------------
//
// @(#)$Id: UserRight.aspx.cs,v 1.0 2013/12/16 9:53:19 lichunhua Exp $
// @(#)$Author: lichunhua  $
// @(#)$Date: 2013/12/16 9:53:19 $
// @(#)$Description:
//
//
//
//                 All Rights Reserved.
//-----------------------------------------------------------------
using System;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using ebay.Dal.CenterDB_SystemTableAdapters;

public partial class UI_SysSet_UserRight : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string userId = Request["id"];
            if (!string.IsNullOrEmpty(userId))
            {
                Bind(userId);                
            }
        }
    }

    void Bind(string userId)
    {
        T_UserrightContextTableAdapter adapter = new T_UserrightContextTableAdapter();
        repeater1.DataSource = adapter.GetRightByUserId(userId);
        repeater1.DataBind();
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        if (Session["UserId"] == null)
        {
            WebUtility.ShowMsg("登陆超时,请重新登陆", this);
            return;
        }
        bool result = false;
        string userId = Request["id"];
        string mUser = Session["UserId"].ToString();

        for (int i = 0; i < repeater1.Items.Count; i++)
        {
            CheckBox chkBox = repeater1.Items[i].FindControl("chkitem") as CheckBox;
            string orignal_val = chkBox.Attributes["orignal"];
            string val = chkBox.Checked.ToString().ToLower();

            if (val == "true" && orignal_val == "false")
            {
                string progid = (repeater1.Items[i].FindControl("progid") as HtmlTableCell).InnerText;
                T_UserRightTableAdapter adapter = new T_UserRightTableAdapter();
                adapter.Insert(userId, progid, "", mUser, DateTime.Now, "", DateTime.Now);
                result = true;
            }
            else if (orignal_val == "true" && val == "false")
            {
                string progid = (repeater1.Items[i].FindControl("progid") as HtmlTableCell).InnerText;
                T_UserRightTableAdapter adapter = new T_UserRightTableAdapter();
                adapter.Delete(userId, progid);
                result = true;
            }
        }
        if (result)
        {
            Response.Write("<script>alert('修改成功!');window.location.href='users.aspx'</script>");
        }
        else {

            WebUtility.ShowMsg("权限分配失败", this);
        }
    }
}
